#include "Expression.h"


#include "ExpressionAdd.h"
#include "ExpressionEquals.h"
#include "ExpressionSub.h"

Expression::Expression()
{
    m_bFirst = true;
    m_charOpr = '0';
}

Expression::~Expression()
{
}

//获取操作符;
char Expression::GetOpr()
{
    return m_charOpr;
}

//解析操作;
uint64_t Expression::Interpreter(ContextInterpreter& context)
{
    Q_UNUSED(context);
    return 0;
}

int64_t Expression::FindNextNumber(ContextInterpreter &context)
{
    int64_t iValue = 0;
    qsizetype index = 0;
    QString strValue = "";
    for (; index < context.m_strCommand.length(); index++)
    {
        QChar chData = context.m_strCommand.at(index);
        if (chData.isNumber()) //是数字;
        {
            strValue.append(chData);
            continue;
        }
        else
        {
            if (index + 1 < context.m_strCommand.length())
            {
                context.m_strCommand = context.m_strCommand.mid(index);
            }
            else
            {
                context.m_strCommand = "";
            }
            break;
        }
    }

    if (strValue.length() > 0)
    {
        iValue = strValue.toInt();
    }
    return iValue;
}

QChar Expression::FindNextOpreation(ContextInterpreter& context)
{
    QChar chValue = '0';
    qsizetype index = 0;
    for (; index < context.m_strCommand.length(); index++)
    {
        QChar chData = context.m_strCommand.at(index);
        if (!chData.isNumber()) //不是数字;
        {
            if (chData == '+' || chData == '-')
            {
                chValue = chData;
                if (index + 1 < context.m_strCommand.length())
                {
                    context.m_strCommand = context.m_strCommand.mid(index + 1);
                }
                else
                {
                    context.m_strCommand = "";
                }
            }
            break;
        }
    }

    return chValue;
}
